package 数组;

import java.util.concurrent.locks.ReentrantLock;

public class subarraySum {
    public static int subarraySum(int[] nums, int k) {
        int ans=0,sum=0;
        int left=0,right=0;
        int n=nums.length;
        if(n==1 &&nums[0]==k){
            return 1;
        }
        while (right<n){
            while (right<n && sum<k){
                sum+=nums[right];
                ++right;
            }
            if(sum==k){
                ++ans;
            }
            sum-=nums[left];
            ++left;

        }

        return nums[n-1]==k?ans+1:ans;
    }


    public static void main(String[] args) {
        System.out.println(subarraySum(new int[]{1},0));

    }

}
